#define CMD_LENGTH			1
#define PARAMS_LENGTH		8
#define PACKETS_PER_FRAME	2
#define PACKET_LENGTH		(CMD_LENGTH + PARAMS_LENGTH)
#define FRAME_LENGTH		(START_SIZE + SRC_SIZE + DST_SIZE + (2 * (PACKETS_PER_FRAME * PACKET_LENGTH)) + CRC_SIZE + STOP_SIZE)

#define START_SIZE	1
#define SRC_SIZE	2
#define DST_SIZE	2
#define CRC_SIZE	4
#define	STOP_SIZE	2

typedef struct {
	unsigned char cmd;
	char params[PARAMS_LENGTH];
} packet_t;

typedef struct {
	packet_t packet[PACKETS_PER_FRAME];
	unsigned char num;
} packets_t;

typedef enum {
	false, true
} bool;

/*
typedef enum {
	beacon,
	data,
	ack
} frame_type_t;

typedef struct {
	char **id;
	unsigned char count;
} path_t;

typedef struct {
	unsigned long sequence_number;
	frame_type_t frame_type;
	unsigned char src;
	unsigned char dst;
	path_t path;
	char data[32];
} frame_t;
*/

typedef enum {
	idle,
	start_received,
	cr_received,
	n_received,
	data_ready
} state_t;

void init_protocol(packets_t *p, unsigned char *frame);
unsigned char get_protocol_data(packets_t *p);
unsigned char add_to_protocol_decoder(unsigned char s);
unsigned char add_packet_to_protocol_encoder(packet_t *p);

unsigned char decode_frame();
unsigned char encode_frame(unsigned char src, unsigned char dst);
